package user

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"project-im/config"
	"project-im/internal/api/request"
	"project-im/internal/model/dao"
)

func Update(c *gin.Context) {
	var json request.Updates
	if err := c.ShouldBindJSON(&json); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	values, _ := c.Get("userId")
	var user dao.ImUser
	config.DB.Where("id=?", values).Limit(1).Find(&user)
	//if user.Password != json.OldPassword {
	//	c.JSON(http.StatusBadRequest, gin.H{
	//		"code":    500,
	//		"message": "原始密码不正确",
	//		"data":    nil,
	//	})
	//}
	//if json.NewPassword != json.ConfirmPassword {
	//	c.JSON(http.StatusBadRequest, gin.H{
	//		"code":    500,
	//		"message": "两次密码不一致",
	//		"data":    nil,
	//	})
	//}
	config.DB.Model(&user).Update("password", json.ConfirmPassword)
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "修改成功",
		"data":    nil,
	})
}
